package cn.com.ddapp.ddm.adapter.commidadapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.bumptech.glide.Glide;

import java.util.List;

import cn.com.ddapp.ddm.AppConfig;
import cn.com.ddapp.ddm.R;
import cn.com.ddapp.ddm.api.OKUtilAPI;
import cn.com.ddapp.ddm.bean.HomeBean;

/**
 * Created by Administrator on 2016/8/30 0030.
 */
public class ThreeAdapter extends RecyclerView.Adapter<ThreeAdapter.MyViewHolder> {

    private Context context;
    List<HomeBean.SortListBean> sortList;
    private LayoutInflater inflater;

    public ThreeAdapter(Context context, List<HomeBean.SortListBean> sortList) {
        this.context = context;
        this.sortList=sortList;
        inflater = LayoutInflater.from(context);
    }

    @Override
    public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = inflater.inflate(R.layout.item_land_view, parent, false);
        return new MyViewHolder(view);
    }

    @Override
    public void onBindViewHolder(MyViewHolder holder, final int position) {
        Glide.with(context).load(OKUtilAPI.imgBaseUrl+ sortList.get(2).getImg()).into(holder.itemImage);
        holder.landtext.setText(sortList.get(2).getName());

        holder.llRoot.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (onItemClickListener != null) {
                    onItemClickListener.onItemClick(v, position);
                }
            }
        });

        holder.llRoot.setOnLongClickListener(new View.OnLongClickListener() {
            @Override
            public boolean onLongClick(View v) {
                if (onItemClickListener != null) {
                    onItemClickListener.onItemLongClick(v, position);
                }
                return true;
            }
        });


    }

    public void setOnItemClickListener(OnItemClickListener onItemClickListener) {
        this.onItemClickListener = onItemClickListener;
    }

    OnItemClickListener onItemClickListener;

    public interface OnItemClickListener {
        void onItemClick(View v, int position);

        void onItemLongClick(View v, int position);
    }


    @Override
    public int getItemCount() {
        return 1;
    }

    class MyViewHolder extends RecyclerView.ViewHolder {
        private ImageView itemImage;
        private TextView landtext;
        private TextView landpirce;
        private LinearLayout llRoot;

        public MyViewHolder(View itemView) {
            super(itemView);
            itemImage = (ImageView) itemView.findViewById(R.id.itemImage);
            landtext = (TextView) itemView.findViewById(R.id.landtext);
//            landpirce = (TextView) itemView.findViewById(R.id.landpirce);
            llRoot = ((LinearLayout) itemView.findViewById(R.id.llRoot));
        }
    }
}